#!/bin/bash

lamp=/web
apache=$lamp/apache
workdir=$(pwd)
usr=web
grp=web

apr() {
	test -e $apache/apr/bin/apr-1-config && return
	cd $workdir
	test -d apr-1.5.2 || tar -xf apr-1.5.2.tar.bz2
	cd apr-1.5.2
	./configure --prefix=$apache/apr || return 
	make || return
	make install
}

apr-util() {
	test -e $apache/apr-util/bin/apr-1-config && return
	cd $workdir
	test -d apr-util-1.5.4 || tar -xf apr-util-1.5.4.tar.bz2
	cd apr-util-1.5.4
	./configure --prefix=$apache/apr-util   \
		--with-apr=$apache/apr/bin/apr-1-config || return
	make || return
	make install
}

httpd() {
	apr
	apr-util
	test -e $apache/apache/bin/apache && return
	cd $workdir
	tar -xf httpd-2.4.23.tar.bz2
	cd httpd-2.4.23
	./configure --prefix=$apache                            \
		--enable-modules=all                            \
		--enable-mods-shared=all                        \
		--enable-so                                     \
		--enable-rewrite                                \
		--with-mpm=prefork                              \
		--with-apr=$apache/apr/bin/apr-1-config         \
		--with-apr-util=$apache/apr-util/bin/apu-1-config || return
	make || return
	make install
}

nginx() {
	prefix=$lamp/nginx
	test -d nginx-1.10.2 || tar -xf nginx-1.10.2.tar.gz
	cd nginx-1.10.2
	./configure --prefix=$prefix                    \
		--user=$usr                        	\
		--group=$grp                       	\
		--http-client-body-temp-path=$prefix/temp/client    \
		--http-proxy-temp-path=$prefix/temp/proxy           \
		--http-fastcgi-temp-path=$prefix/temp/fastcgi       \
		--http-uwsgi-temp-path=$prefix/temp/uwsgi           \
		--http-scgi-temp-path=$prefix/temp/scgi             \
		--with-http_gzip_static_module      \
		--with-http_stub_status_module      \
		--with-http_ssl_module || return
	make -j4 || return
	make install
}

php() {
	prefix=$lamp/php
	cd $workdir
	test -d php-7.0.13 || tar -xf php-7.0.13.tar.bz2
	cd php-7.0.13
	./configure --prefix=$prefix                   \
		--with-apxs2=$apache/bin/apxs  \
		--enable-mysqlnd                    \
		--with-mysqli=mysqlnd               \
		--with-pdo-mysql=mysqlnd            \
		--with-config-file-path=$prefix/etc         \
		--with-config-file-scan-dir=$prefix/etc/conf.d     \
		--with-curl                             \
		--with-zlib                             \
		--enable-zip                            \
		--enable-maintainer-zts                 \
		--with-gd                               \
		--with-jpeg-dir=/usr                    \
		--with-png-dir=/usr                     \
		--with-xpm-dir=/usr                     \
		--with-freetype-dir=/usr                \
		--enable-gd-native-ttf                  \
		--enable-pcntl                          \
		--enable-sysvmsg                        \
		--enable-sysvsem                        \
		--enable-sysvshm                        \
		--enable-shmop                          \
		--enable-sockets                        \
		--enable-ftp                            \
		--enable-xml                            \
		--with-xmlrpc                           \
		--enable-soap                           \
		--enable-libxml                         \
		--enable-mbstring                       \
		--enable-mbregex                        \
		--with-gettext                          \
		--with-openssl                          \
		--with-mhash                            \
		--with-mcrypt                           \
		--enable-bcmath                         \
		--enable-fpm                            \
		--enable-opcache                        \
		--enable-inline-optimization            \
		--disable-debug                         \
		--enable-dtrace                         \
        OPENSSL_INCDIR=/usr/include             \
        OPENSSL_LIBDIR=/lib/x86_64-linux-gnu    \
		LIBS=-liconv || return
	make -j4 || return
	make install
}

nginx
# php

